package ttot.transitions.plugin;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import scala.collection.JavaConversions;
import scala.collection.immutable.Set;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @goal find
 * @requiresProject true
 * @requiresDependencyResolution test
 */
public class TransitionFinderMojo extends AbstractMojo {

    /**
     * @parameter expression="${project}"
     * @required
     * @readonly
     */
    private MavenProject project;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        Path testOutputPath = Paths.get(project.getBuild().getTestOutputDirectory()).toAbsolutePath();
        Set<Path> classes = ClassFinder.find(testOutputPath);
        Set<Class<?>> classSet = TransitionFinder.find(testOutputPath, classes);
        for(Class<?> c : JavaConversions.asJavaSet(classSet)) {
            System.out.println("found transition: " + c.getCanonicalName());
        }
    }
}
